package com.wjp.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@Slf4j
public class FooController {

    @Autowired
    private ChatClient chatClient;

    @GetMapping("/ai/generate")
    public String generate(@RequestParam(value = "message", defaultValue = "推荐一个公众号") String message) {
        ChatClient.CallResponseSpec call = chatClient.prompt(message).call();
        String content = call.content();
        return content;
    }

    @GetMapping(value = "/chat", produces = "text/html;charset=utf-8")
    public Flux<String> call(@RequestParam String input) {
        return chatClient.prompt(input).stream().content();
    }

}
